package com.ruoyi.web.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gitee.deeround.jdbchelper.DbAction;
import com.ruoyi.core.util.MapstructUtils;
import com.ruoyi.web.domain.SysMod;
import com.ruoyi.web.domain.SysModColumn;
import com.ruoyi.web.entity.system.SysModInfoVo;
import com.ruoyi.web.mapper.SysModColumnMapper;
import com.ruoyi.web.mapper.SysModMapper;
import com.ruoyi.web.service.SysModService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class SysModServiceImpl extends BaseService<SysModMapper, SysMod, SysMod> implements SysModService {

    @Autowired
    private SysModColumnMapper sysModColumnMapper;

    @Autowired
    private DbAction dbAction;

    @Override
    public String getNextId() {

        Integer modId = dbAction.queryForInteger("select max(mod_id) mod_id from sys_mod");

        return modId == null || modId < 10000 ? "10000" : modId + 1 + "";
    }

    @Override
    public SysModInfoVo getInfoById(String id) {
        SysMod mod = getById(id);
        SysModInfoVo modInfo = MapstructUtils.convert(mod, SysModInfoVo.class);
        List<SysModColumn> columns = sysModColumnMapper.selectVoList(Wrappers.<SysModColumn>query().lambda().eq(SysModColumn::getModId, id));
        modInfo.setColumns(columns);
        return modInfo;
    }
}
